﻿using DBServer.Selenium.Extenium.Exception;
using DBServer.Selenium.Extenium.Path;
using Selenium;

namespace DBServer.Selenium.Extenium.Fixtures
{
    public class RadioFixture : ExtComponentFixture
    {
        private readonly IPath _path;

        public RadioFixture(ISelenium driver, IPath path)
            : base(driver, path)
        {
            _path = path;
        }

        public void Select()
        {
            var command = _path + ".setValue(true);";
            SafeExec(command);
        }

        public void RequireSelected()
        {
            var command = _path + ".getValue();";
            var selected = bool.Parse(SafeExec(command));
            if ( !selected )
            {
                throw new ExteniumException("Radio was not selected");
            }
        }

        public void RequireUnselected()
        {
            var command = _path + ".getValue();";
            var selected = bool.Parse(SafeExec(command));
            if ( selected )
            {
                throw new ExteniumException("Radio was selected");
            }
        }
    }
}